﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using EgeUniversity.SolarCarProject;

namespace Pit
{
	/// <summary>
	/// Interaction logic for ControlWindow.xaml
	/// </summary>
	public partial class ControlWindow : Window
	{
		MainWindow win = (MainWindow)App.Current.MainWindow;
		public ControlWindow()
		{
			InitializeComponent();
		}

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			myGPSLat.Tag		= CarValues.GPS_Latitude;
			myGPSLong.Tag		= CarValues.GPS_Longitude;
			myHiz.Tag			= CarValues.Velocity;
			myAku.Tag			= CarValues.BatteryStateOfCharge;
			myAkuSicaklik.Tag	= CarValues.BatteryTemperature;
			myPanelSicaklik.Tag = CarValues.PV_Temperature1;
			myPV_V.Tag			= CarValues.PV_Voltage1;
			myPV_A.Tag			= CarValues.PV_Current1;
			myAku_V.Tag			= CarValues.BatteryVoltage;
			myAku_A.Tag			= CarValues.BatteryCurrent;
		}

		Point p = new Point(27.270942, 38.433657);
		private void Window_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			Slider s = e.OriginalSource as Slider;
			if (s != null && s.Tag != null)
			{
				switch ((CarValues)s.Tag)
				{
					case CarValues.GPS_Latitude			: p.Y = s.Value; win.Car.GPSLocation = p; break;
					case CarValues.GPS_Longitude		: p.X = s.Value; win.Car.GPSLocation = p; break;
					case CarValues.Velocity				: win.Car.Velocity				= s.Value; break;
					case CarValues.BatteryStateOfCharge	: win.Car.BatteryStateOfCharge	= s.Value; break;
				}
			}
		}

		private void Window_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.Key == Key.Escape)
				this.Close();
		}
	}
}
